from twisted.protocols.basic import LineReceiver

class ModuleProtocol(LineReceiver):
    
    def __init__(self,logger,driver):
        self.logger = logger
        assert(driver[0:19] == '/dev/tty.usbserial-')
        self.id = driver[19:]
    
    def lineReceived(self,line):
        print '[%s] %s' % (self.id,line)
        tokens = line.split(' ')
        if tokens[0] == 'LOG':
            self.logger.record(tokens[1],tokens[2:])